import requests

url = 'https://fanyi.baidu.com/sug'

# 在有身份验证的网站上 要修改请求头 来正常访问网站
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36'
}

str=input('请输入您要翻译的内容')

data = {'kw':str}

res = requests.post(url=url, headers=headers,data=data)
res.encoding = 'utf-8'
status_code = res.status_code
if status_code == 200:
    result=res.json()
    print(res.json())
    if result['errno']==0:
        print('响应成功')
        k=result['data'][0]['k']
        v=result['data'][0]['v'].split(';')[-2]
        print(k,'===============',v)

